#include <iostream>
using namespace std;

signed main()
{
    int n,m,sum[100005] = {0};
    cin>>n;
    for(int i=1;i<=n;i++){
        int t;
        cin>>t;
        sum[i+1] = sum[i]+t;
    }
    cin>>m;
    for(int i=0;i<m;i++){
        int p,q;
        cin>>p>>q;
        if(p>q)    swap(q,p);
        int l = sum[q]-sum[p];
        int r = sum[n+1]-sum[q]+sum[p]-sum[1];
        if(l<r)    cout<<l<<"\n";
        else    cout<<r<<"\n";
    }
    return 0;
}
